home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / DJLSR106.ARJ / FSTREAM.CC < prev    next >
C/C++ Source or Header  |  1992-03-30  |  3KB  |  123 lines

  1. //    This is part of the iostream library, providing input/output for C++.
  2. //    Copyright (C) 1991 Per Bothner.
  3. //
  4. //    This library is free software; you can redistribute it and/or
  5. //    modify it under the terms of the GNU Library General Public
  6. //    License as published by the Free Software Foundation; either
  7. //    version 2 of the License, or (at your option) any later version.
  8. //
  9. //    This library is distributed in the hope that it will be useful,
  10. //    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12. //    Library General Public License for more details.
  13. //
  14. //    You should have received a copy of the GNU Library General Public
  15. //    License along with this library; if not, write to the Free
  16. //    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  
  18. #define _STREAM_COMPAT
  19. #include "ioprivate.h"
  20. #include <fstream.h>
  21. #ifdef __GNUG__
  22. #pragma implementation "fstream.h"
  23. #endif
  24.  
  25. ifstream::ifstream()
  26. {
  27.     _strbuf = new filebuf();
  28. }
  29.  
  30. ifstream::ifstream(int fd)
  31. {
  32.     _strbuf = new filebuf(fd);
  33. }
  34.  
  35. ifstream::ifstream(const char *name, int mode, int prot)
  36. {
  37.     _strbuf = new filebuf();
  38.     if (!rdbuf()->open(name, mode, prot))
  39.     set(ios::badbit);
  40.     _flags &= ~ios::dont_close;
  41. }
  42.  
  43. ofstream::ofstream()
  44. {
  45.     _strbuf = new filebuf();
  46. }
  47.  
  48. ofstream::ofstream(int fd)
  49. {
  50.     _strbuf = new filebuf(fd);
  51. }
  52.  
  53. ofstream::ofstream(const char *name, int mode, int prot)
  54. {
  55.     _strbuf = new filebuf();
  56.     if (!rdbuf()->open(name, mode, prot))
  57.     set(ios::badbit);
  58.     _flags &= ~ios::dont_close;
  59. }
  60.  
  61. #if 0
  62. static int mode_to_sys(enum open_mode mode)
  63. {
  64.     return O_WRONLY;
  65. }
  66.  
  67. static char* fopen_cmd_arg(io_mode i)
  68. {
  69.     return "w";
  70. }
  71. #endif
  72.  
  73. void ifstream::open(const char *name, int mode, int prot)
  74. {
  75.     if (!rdbuf()->open(name, mode, prot))
  76.     set(ios::badbit);
  77. }
  78.  
  79. void ifstream::close()
  80. {
  81.     rdbuf()->close();
  82. }
  83.  
  84. void ofstream::close()
  85. {
  86.     rdbuf()->close();
  87. }
  88.  
  89. void ofstream::open(const char *name, int mode, int prot)
  90. {
  91.     if (!rdbuf()->open(name, mode, prot))
  92.     set(ios::badbit);
  93. }
  94.  
  95. fstream::fstream()
  96. {
  97.     _strbuf = new filebuf();
  98. }
  99.  
  100. fstream::fstream(int fd)
  101. {
  102.     _strbuf = new filebuf(fd);
  103. }
  104.  
  105. fstream::fstream(const char *name, int mode, int prot=0664)
  106. {
  107.     _strbuf = new filebuf();
  108.     if (!rdbuf()->open(name, mode, prot))
  109.     set(ios::badbit);
  110.     _flags &= ~ios::dont_close;
  111. }
  112.  
  113. void fstream::open(const char *name, int mode, int prot=0664)
  114. {
  115.     if (!rdbuf()->open(name, mode, prot))
  116.     set(ios::badbit);
  117. }
  118.  
  119. void fstream::close()
  120. {
  121.     rdbuf()->close();
  122. }
  123.